package server.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import server.business.mapper.BloodSampleMapper;
import server.business.mapper.BloodSampleStateMapper;
import server.business.pojo.BloodSample;
import server.business.service.BloodSampleReviewService;
import server.business.service.BloodSampleService;
import server.business.utils.Result;
import server.business.vo.ResultExpand;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/bloodSample")
public class BloodSampleController {
    @Autowired
    private BloodSampleMapper bloodSampleMapper;
    @Autowired
    private BloodSampleService bloodSampleService;
    @Autowired
    private BloodSampleStateMapper bloodSampleStateMapper;
    @Autowired
    private BloodSampleReviewService bloodSampleReviewService;
    /**
     * 根据bloodId,查询血样
     */
    @RequestMapping("/normal/selectSampleByBloodId")
    @ResponseBody
    public Result selectSampleByBloodId(String bloodId) {
        BloodSample bloodSample=bloodSampleMapper.selectByBloodId(bloodId);
        Result result = new Result();
        result.setData(bloodSample);
        return result;
    }

//    @RequestMapping("/index")
//    public String toIndex(){
//        return "index-tabs";
//    }
//
//    @RequestMapping("/blood_sample")
//    public String toSample(){
//        return "pages/sample_information";
//    }

    /**
     * 查询数据
     */
    @RequestMapping("/normal/query")
    @ResponseBody
    public List<BloodSample> queryData(){
        List<BloodSample> list = bloodSampleService.queryData();
        return list;
    }

    /**
     * 删除通过id
     */
    @PutMapping("/normal/deleteById")
    @ResponseBody
    public server.business.vo.Result deleteById(Integer id){
        server.business.vo.Result result = new server.business.vo.Result();
        result = bloodSampleService.deleteById(id);
        return result;
    }

    /**
     * 获取页面
     *血液标本分页查询
     */
    @RequestMapping("/normal/listByPage")
    @ResponseBody
    public ResultExpand getPage(HttpServletRequest request, HttpServletResponse response){
        ResultExpand resultExpand = new ResultExpand();
        resultExpand = bloodSampleService.getPage(request, response);
        return resultExpand;
    }

    /**
     * 搜索血液样本
     *
     * @param request  请求
     * @param response 响应
     * @return {@link ResultExpand}
     */
    @RequestMapping("/normal/searchSample")
    @ResponseBody
    public ResultExpand searchSample(HttpServletRequest request, HttpServletResponse response){
        ResultExpand resultExpand = new ResultExpand();
        resultExpand = bloodSampleService.searchSample(request, response);
        return resultExpand;
    }

    /**
     * 增加血液样本
     *
     * @param sampleData 样本数据
     * @return {@link server.business.vo.Result}
     */
    @RequestMapping(value = "/normal/addSample")
    @ResponseBody
    public server.business.vo.Result addBloodSample(@RequestBody BloodSample sampleData) {
        server.business.vo.Result result = new server.business.vo.Result();
        result = bloodSampleService.addBloodSample(sampleData);
        return result;
    }

    /**
     * 签收样本
     *
     * @param sampleData 样本数据
     * @return {@link String}
     */
    @RequestMapping(value = "/normal/receiveSample")
    @ResponseBody
    public server.business.vo.Result receiveSample(@RequestBody BloodSample sampleData) {
        server.business.vo.Result result = new server.business.vo.Result();
        result = bloodSampleService.receiveSample(sampleData);
        return result;
    }

    /**
     * 血液样品出库
     *
     * @param sampleData 样本数据
     * @return {@link server.business.vo.Result}
     */
    @RequestMapping("/normal/outSample")
    @ResponseBody
    public server.business.vo.Result outSample(@RequestBody BloodSample sampleData){
        server.business.vo.Result result = new server.business.vo.Result();
        result = bloodSampleService.outSample(sampleData);
        return result;
    }

    /**
     * 丢弃血液样品
     *
     * @param sampleData 样本数据
     * @return {@link server.business.vo.Result}
     */
    @RequestMapping("/normal/discardSample")
    @ResponseBody
    public server.business.vo.Result discardSample(@RequestBody BloodSample sampleData){
        server.business.vo.Result result = new server.business.vo.Result();
        result = bloodSampleService.discardSample(sampleData);
        return result;
    }

    /**
     * 下载excel
     *
     * @param request  请求
     * @param response 响应
     */
    @RequestMapping("/normal/downloadExcel")
    public void downloadExcel(HttpServletRequest request, HttpServletResponse response){
        bloodSampleService.downloadExcel(request, response);
    }
}
